package draw;

import javax.swing.*;
import java.awt.*;

/**
 * Created with IntelliJ IDEA
 * Description:画图学习
 * User:22954
 * Date:2024-02-29
 * Time:23:16
 */
public class DrawCircular extends JFrame{//Frame相当于画框
    //创造画板
    private MyPanel mp = null;
    public static void main(String[] args) {
        new DrawCircular();
    }
    public DrawCircular(){
        //实例化画板
        mp = new MyPanel();
        //将画板添加到画框(窗口)
        super.add(mp);
        //设定窗口大小
        super.setSize(600,400);
        //显示窗口
        super.setVisible(true);
        //关闭窗口时程序结束
        super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
class MyPanel extends JPanel{//Panel相当于画板
    /*
    JPanel extends JComponent
    JComponent提供两个重要绘图方法:
        paint(Graphics g)绘制组件外观
        repaint()刷新组件外观
    paint()方法被调用的机制:1.组件第一次在屏幕显示时
                         2.窗口最小化再最大化
                         3.窗口大小发生变化
                         4.repaint()被调用
     */
    @Override
    public void paint(Graphics g) {//Graphics相当于画笔
        super.paint(g);//调用父类初始化
//        System.out.println("is used");
        g.drawOval(10,10,100,100);//画圆
    }
}